#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<int> findAnagrams(string s, string p) {
    int l = p.size();
    if (s.size() < l)    return {};
    vector<int> m1(26), m2(26);
    for (int i = 0; i < l; i++)
    {
        m1[s[i] - 'a']++;
        m2[p[i] - 'a']++;
    }

    vector<int> res;
    if (m1 == m2)    res.push_back(0);
    for (int i = 0; i < s.size() - l; i++)
    {
        m1[s[i + l] - 'a']++;
        m1[s[i] - 'a']--;
        if (m1 == m2)    res.push_back(i + 1);
    }

    return res;
}

int main()
{
    findAnagrams("cbaebabacd", "abc");
    return 0;
}